*******************************
***** CBI and Banking Crises **
***** APSR Replication       **
***** Main Paper 			 **
***** 10/3/2021              **   

use "Crises_CBI_RepData.dta", clear

***********************************************
*** Defining globals to be used in plotting ***
***********************************************

global dvt local dvtitle = e(depvar)
global plot marginsplot, yline(0,lcolor(red)) recast(scatter) ytitle(`dvtitle') addplot(hist EmpM if e(sample),color(cyan%13) yaxis(2) width(0.15) legend(off) ylabel(,noticks nolabel axis(2)) ytitle("", axis(2)))

global dv_U d.logunemp_ilo ld.logunemp_ilo
global dv_Cr d.logdomcredit ld.logdomcredit
global dv_St d.logstockvalue ld.logstockvalue

program define danmplot

syntax , cvar(varname)
local dvtitle = e(depvar)

quietly marginsplot, yline(0,lcolor(red)) recastci(rarea) graphregion(color(white)) plotopts(msymbol(o) lcolor(navy) ytitle(`dvtitle') msize(tiny) mcolor(navy)) ci1opts(fintensity(60) color(navy%60)) ///
xlabel(#20,angle(-45) grid glcolor(%10)) ///
addplot(hist `cvar' if e(sample), yaxis(2) legend(off) color(cyan%15) ylabel(,noticks nolabel axis(2)) ytitle("", axis(2)))

end

*** descriptives ***
sum d.logunemp_ilo if BCsys==1 & highcbi==0, d
sum d.logunemp_ilo if BCsys==1 & highcbi==1, d

******************************************************
***** TABLE 1 & FIG1: CBI FIXED EFFECTS **************
******************************************************
global cbiXsm d.KOFEcGIdf l.KOFFiGIdj d.fiscal l.logcpi l.loggdppc l.EquityBankRatio d.range 
global cbiXbig d.KOFEcGIdf l.KOFFiGIdj d.fiscal l.loggdppc leftgov l.eldem l.EquityBankRatio l.logtotresgdp l.default l.logcpi d.range l.range peg CrBubble5dum l.logcpi_Reg l.logevol__Reg uscrisis t_lastBCsys

******************************

quietly {
xtreg $dv_U c.cbi##c.BCsys $cbiXsm  if nondict==1, cl(ccode) fe
est sto t1m1
quietly margins, dydx(BCsys) at(cbi=(0.1(0.05)0.9)) force
danmplot, cvar(cbi)
graph save "cbi1.gph", replace
xtreg $dv_U c.cbi##c.BCsys $cbiXbig  if nondict==1, cl(ccode) fe
est sto t1m2

xtreg $dv_Cr  c.cbi##c.BCsys $cbiXsm  if nondict==1, cl(ccode) fe
est sto t1m3
quietly margins, dydx(BCsys) at(cbi=(0.1(0.05)0.9)) force
danmplot, cvar(cbi)
graph save "cbi2.gph", replace
xtreg $dv_Cr  c.cbi##c.BCsys $cbiXbig  if nondict==1, cl(ccode) fe
est sto t1m4

xtreg $dv_St  c.cbi##c.BCsys $cbiXsm  if nondict==1, cl(ccode) fe
est sto t1m5
quietly margins, dydx(BCsys) at(cbi=(0.1(0.05)0.9)) force
danmplot, cvar(cbi)
graph save "cbi3.gph", replace
xtreg $dv_St  c.cbi##c.BCsys $cbiXbig  if nondict==1, cl(ccode) fe
est sto t1m6
}
** table 1 **
esttab t1m* , compress se nogaps label b(3) scalar(N_g g_avg) title("Table 1: CBI and Banking Crises") drop() star(* 0.1 ** 0.05 *** 0.001) replace

graph combine "cbi1.gph" "cbi2.gph" "cbi3.gph", title(Figure 1: Marginal Effect of Banking Crises across CBI)

******************************************************
****************** CBI SUBSET MODELS *****************
******************************************************
*** table 2

global subX   preBC_KOFFiGIdj preBC_logcred2dep preBC_CAdef d.log_IMFgdp cbreform d.range d.fiscal peg CrBubble5dum l.(EquityBankRatio KOFEcGIdf FD default logcpi  ) 

*** UNEMP ***
quietly {
xtreg d.logunemp_ilo  l.cbi d.cbi  i.geocode   if nondict==1 & BCsys==1, cl(ccode) 
est sto t2m1
xtreg d.logunemp_ilo  l.cbi d.cbi  $subX  i.geocode if nondict==1 & BCsys==1, cl(ccode)
est sto t2m11
*** CREDIT ***
xtreg d.logdomcredit  l.cbi d.cbi  i.geocode  if nondict==1 & BCsys==1, cl(ccode) 
est sto t2m2
xtreg d.logdomcredit  l.cbi d.cbi $subX  i.geocode  if nondict==1 & BCsys==1, cl(ccode) 
est sto t2m22
*** STOCKS ***
xtreg d.logstockvalue  l.cbi d.cbi   i.geocode if nondict==1 & BCsys==1, cl(ccode) 
est sto t2m3
xtreg d.logstockvalue  l.cbi d.cbi  $subX i.geocode if nondict==1 & BCsys==1, cl(ccode) 
est sto t2m33
*quietly margins, at(l.cbi=(0.1(0.05)0.9)) force
*marginsplot, yline(0,lcolor(red)) recastci(rarea) addplot(hist cbi if e(sample), yaxis(2) width(0.02) )
}
esttab t2m1 t2m11 t2m2 t2m22 t2m3 t2m33 , compress se nogaps label b(3) scalar(N_g g_avg) title("Table 2: Crisis Years Models") addn(regional fixed effects) drop(*geocode) star(* 0.1 ** 0.05 *** 0.001) replace 

**************************************************************
****************** Employment Mandate Models *****************
**************************************************************
*** FIGURE 3
********** *****

quietly {
xtreg $dv_U c.EmpM##c.BCsys##c.FCBI_dum $cbiXsm  if nondict==1, cl(ccode) fe
est sto at4m1
quietly margins, dydx(BCsys) at(EmpM=(1(1)6) FCBI_dum==1)  force
$dvt
$plot
graph save "EM1.gph", replace

xtreg $dv_U c.EmpM##c.BCsys##c.FCBI_dum $cbiXbig  if nondict==1, cl(ccode) fe
est sto at4m2

xtreg $dv_Cr c.EmpM##c.BCsys##c.FCBI_dum $cbiXsm  if nondict==1, cl(ccode) fe
est sto at4m3
quietly margins, dydx(BCsys) at(EmpM=(1(1)6) FCBI_dum==1)  force
$dvt
$plot
graph save "EM2.gph", replace

xtreg $dv_Cr c.EmpM##c.BCsys##c.FCBI_dum $cbiXbig  if nondict==1, cl(ccode) fe
est sto at4m4

xtreg $dv_St c.EmpM##c.BCsys##c.FCBI_dum $cbiXsm  if nondict==1, cl(ccode) fe
est sto at4m5
quietly margins, dydx(BCsys) at(EmpM=(1(1)6) FCBI_dum==1)  force
$dvt
$plot
graph save "EM3.gph", replace

xtreg $dv_St c.EmpM##c.BCsys##c.FCBI_dum $cbiXbig  if nondict==1, cl(ccode) fe
est sto at4m6
}

*** Appendix Table AT4 ***
esttab at4m* , compress se nogaps label b(3) scalar(N_g g_avg) title("Table AT4: Employment Mandate Crisis Models") drop() star(* 0.1 ** 0.05 *** 0.001) replace

**** Figure 3 ****
graph combine "EM1.gph" "EM2.gph" "EM3.gph", title(Figure 3: Effect of Banking Crises Across Employment Mandate Index) subtitle(At High Functional Independence)

**************************************
***** REAL INTEREST RATE MODEL *******
**************************************
**** FIGURE 4
global cbiXsm d.KOFEcGIdf l.KOFFiGIdj d.fiscal l.logcpi l.loggdppc l.EquityBankRatio d.range 
global cbiXbig_a d.KOFEcGIdf l.KOFFiGIdj d.fiscal l.loggdppc leftgov l.eldem l.EquityBankRatio l.logtotresgdp l.default l.logcpi d.range l.range peg CrBubble5dum l.logcpi_Reg l.logevol__Reg uscrisis 

xtreg  d.logIntReal ld.logIntReal  c.FCBI_dum##c.EmpM##c.BCsys $cbiXsm  year if nondict==1 , vce(cluster ccode) fe
est sto at_realint1
quietly margins, dydx(BCsys) at(EmpM=(1(1)6) FCBI_dum=(1)) force
$dvt
$plot
graph save "Fig4_RealInt.gph", replace

xtreg  d.logIntReal ld.logIntReal  c.FCBI_dum##c.EmpM##c.BCsys $cbiXbig_a   if nondict==1 , vce(cluster ccode) fe
est sto at_realint2

*** Appendix Table AT5 ***
esttab at_realint1 at_realint2 ,  se nogaps label b(3) scalar(N_g g_avg) title("Table AT5_Real Interest Rate Models")  star(* 0.1 ** 0.05 *** 0.001) replace

************************************
********* INFLATION OUTCOME ********
************************************
*** table 3

xtreg logcpi l.logcpi EmpM   openness   ka_open  eldem polconiii i.pegtype range logdebtgdp growth loggdppc   l.evol_l5m  year    if nondict==1 & FCBI_dum==0, cl(ccode) fe
est sto t3m1

xtreg logcpi l.logcpi EmpM   openness   ka_open  eldem polconiii i.pegtype range logdebtgdp growth loggdppc   l.evol_l5m  year    if nondict==1 & FCBI_dum==1, cl(ccode) fe
est sto t3m2

esttab t3m1 t3m2 , compress se nogaps label b(3) scalar(N_g g_avg) title("Table 3: Mandate Inflation Models")  star(* 0.1 ** 0.05 *** 0.001) mtitle("Low F_CBI" "High F_CBI")


************************************
********** CBI IV MODELS ***********
************************************
**** FIGURE 5
*** creating the PCA instrument ***
pca cbi_EGlobe_sm cbi_POLcat cbi_GDPcat
*predict CBI_IV_PCA

*** testing IV strength ***
local iv1  CBI_IV_PCA

quietly areg cbi ld.logunemp_ilo  cl.BCsys##c.`iv1'   eldem__Reg KOFEcGIdj_RegAve , vce(cluster ccode) absorb(ccode)
test l.BCsys  `iv1'  cl.BCsys#c.`iv1'   

quietly areg cbi_BCsys  ld.logunemp_ilo  cl.BCsys##c.`iv1'    $cbiXsm   eldem__Reg KOFEcGIdj_RegAve, vce(cluster ccode) absorb(ccode)
test l.BCsys  `iv1'  cl.BCsys#c.`iv1'  
*******
*******

global ivX d.KOFEcGIdf l.KOFFiGIdj d.fiscal l.logcpi l.loggdppc l.EquityBankRatio d.range logevol__Reg 
global cbiIV1 CBI_IV_PCA 

**** IV w/ regional fixed effects **** 
**Unemp**
quietly {
ivregress 2sls d.logunemp_ilo ld.logunemp_ilo  $ivX  i.geocode  (c.cbi##c.BCsys = cl.BCsys##cl.$cbiIV1) if nondict==1 , vce(cluster ccode) 
est sto olsiv1
quietly margins, dydx(BCsys) at(cbi=(0.1(0.05)0.9)) force
danmplot, cvar(cbi)
graph save "ivc1.gph", replace
**credit**
ivregress 2sls d.logdomcredit ld.logdomcredit  $ivX  i.geocode (c.cbi##c.BCsys = cl.BCsys##cl.$cbiIV1 )  if nondict==1 , vce(cluster ccode) 
est sto olsiv2
quietly margins, dydx(BCsys) at(cbi=(0.1(0.05)0.9)) force
danmplot, cvar(cbi)
graph save "ivc2.gph", replace
**stocks**
ivregress 2sls d.logstockvalue ld.logstockvalue  $ivX i.geocode (c.cbi##c.BCsys = cl.BCsys##cl.$cbiIV1 )  if nondict==1, vce(cluster ccode) 
est sto olsiv3
quietly margins, dydx(BCsys) at(cbi=(0.1(0.05)0.9)) force
danmplot, cvar(cbi)
graph save "ivc3.gph", replace
}

**** Figure 5 ****
graph combine "ivc1.gph" "ivc2.gph" "ivc3.gph", title("Figure 5: CBI Instrumental Variable Models") subtitle("Marginal Effect of Banking Crises")

**** IV w/ country fixed effects ****

quietly {
ivregress 2sls d.logunemp_ilo ld.logunemp_ilo  $ivX  i.ccode  (c.cbi##c.BCsys = cl.BCsys##cl.$cbiIV1) if nondict==1 , vce(cluster ccode) 
est sto olsiv4
quietly margins, dydx(BCsys) at(cbi=(0.1(0.05)0.9)) force
danmplot, cvar(cbi)
graph save "ivc4.gph", replace
**credit**
ivregress 2sls d.logdomcredit ld.logdomcredit  $ivX  i.ccode (c.cbi##c.BCsys = cl.BCsys##cl.$cbiIV1 )  if nondict==1 , vce(cluster ccode) 
est sto olsiv5
quietly margins, dydx(BCsys) at(cbi=(0.1(0.05)0.9)) force
danmplot, cvar(cbi)
graph save "ivc5.gph", replace
**stocks**
ivregress 2sls d.logstockvalue ld.logstockvalue  $ivX i.ccode (c.cbi##c.BCsys = cl.BCsys##cl.$cbiIV1 )  if nondict==1, vce(cluster ccode) 
est sto olsiv6
quietly margins, dydx(BCsys) at(cbi=(0.1(0.05)0.9)) force
danmplot, cvar(cbi)
graph save "ivc6.gph", replace
}

** Appendix Figure AF2
*graph combine "ivc4.gph" "ivc5.gph" "ivc6.gph", title("Figure AF2_ CBI IV Models, fixed effects")

*** Appendix Table AT1 ***
esttab olsiv* , compress se nogaps label b(3) scalar(N_g g_avg) title("Table AT1: CBI IV Models") drop(*ccode *geocode)  star(* 0.1 ** 0.05 *** 0.001) replace

